from docx import Document
import pandas as pd
doc=Document('艺体大赛.docx')
index,key,value=[],[],[]
table_index=0
for tb in doc.tables:

 table_index += 1

 row_index=0

 for row in tb.rows:
     row_index+=1
     for cell in row.cells:
         text=""
         for p in cell.paragraphs:   ##如果cell中有多段，即有回车符
             text+=p.text
         if row_index%2==0:
             value.append(text) #偶数行为值
             index.append(table_index) #这行也可以放在else中
         else:
             key.append(text) #奇数行为属性


df=pd.DataFrame({'table_index':index,'key':key,'value':value})
df=df.drop_duplicates(['table_index','key'])
df1=df.pivot(index='table_index',columns='key',values='value')

# df1.columns=list(df1.columns)
# df1.index=list(df1.index)
# print(value)

# data = pd.read_excel('工作簿1.xlsx',engine='openpyxl') #打开表格
#
# dataframe1 = pd.DataFrame(data=data,columns=['1','2','3','4','5','6','7','8','9','10'])
# print(dataframe1.isna())
# columns_list = data.columns.tolist()

# for column in columns_list:
    # print(column)
# FF = data.loc[(data['OBJECTID'] == 0)] #搜索OBJECTID中等于0的值

# print(FF)
# FF.to_excel('o.xlsx')